package org.jw.wishlist.resolver;

import org.springframework.web.client.RestTemplate;

/**
 * @author Jiawei Zhao
 */
public class ItemSourceResolverFactory {

  private final String linkCode;

  private final RestTemplate restTemplate;

  public ItemSourceResolverFactory(String linkCode, RestTemplate restTemplate) {
    this.linkCode = linkCode;
    this.restTemplate = restTemplate;
  }

  public ItemSourceResolver getResolver() {
    if (linkCode.contains("//m.tb.cn")) {
      return new TaobaoItemSourceResolver(restTemplate);
    } else if (linkCode.contains("//item.m.jd.com")) {
      return new JdItemSourceResolver(restTemplate);
    } else if (linkCode.contains("//u.163.com")) {
      return new WangYiItemSourceResolver(restTemplate);
    } else if (linkCode.contains("//m.haohaozhu.cn")) {
      return new HaoHaoZhuSourceResolver(restTemplate);
    } else if (linkCode.contains("//www.hpoi.net.cn")) {
      return new HpoiItemSourceResolver(restTemplate);
    }

    throw new IllegalStateException("无法解析该口令: " + linkCode);
  }

}
